--------------------------------------------------------------------------------
-- Company: 	 Synapse
-- Module Name:    IF_ID_PC - Behavioral
--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity IF_ID_PC is

    Port ( 	clk 							: in std_logic;
	 			reset 						: in std_logic;  
				instructionWrite 			: in std_logic;
				instruction 				: in std_logic_vector(15 downto 0); -- from memory
	 			nextProgramCounter		: in std_logic_vector(15 downto 0);
				currentProgramCounter	: out std_logic_vector(15 downto 0);
				opcode 						: out std_logic_vector(7 downto 0);
				addressA 					: out std_logic_vector(3 downto 0);
				
				addressB 					: out std_logic_vector(3 downto 0);
				immediate					: out std_logic_vector(7 downto 0));

end IF_ID_PC;
architecture Behavioral of IF_ID_PC is
begin

	process (clk, reset)
	begin

		if(reset = '0') then
			currentProgramCounter <= "0111111111111111";
			opcode(7 downto 4) <= (others => '0');
			opcode(3 downto 0) <= (others => '0');
			addressA <= (others => '0');
			addressB <= (others => '0');
			immediate <= (others => '0');
        
		elsif (rising_edge(clk)) then
			currentProgramCounter <= nextProgramCounter;
		        if (instructionWrite = '1') then
       				opcode(7 downto 4) <= instruction(15 downto 12);
				opcode(3 downto 0) <= instruction(7 downto 4);
				addressA <= instruction(11 downto 8);
				addressB <= instruction(3 downto 0);
				immediate <= instruction(7 downto 0);
                end if;
        
		end if;

	end process;

end Behavioral;

